package org.lee;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.*;

/**
 * @author jackielee
 * @version 1.0
 * @description App
 * @date 2021/6/30
 **/
public class App {
    public static void main2(String[] args) {

        /**
         * FixedThreadPool
         * CachedThreadPool
         * SingleThreadExecutor
         * ScheduledThreadPool
         * SingleScheduledThreadExecutor
         * ForkJoinPool
         *
         * Policy:
         * AbortPolicy
         * DiscardPolicy
         * DiscardOldestPolicy
         * CallerRunsPolicy
         */

//         Executors.newFixedThreadPool()
//        Executors.newCachedThreadPool()
//        Executors.newScheduledThreadPool()
//        Executors.newSingleThreadExecutor()
//        Executors.newSingleThreadScheduledExecutor()
//        new ForkJoinPool()

        ScheduledExecutorService service = Executors.newScheduledThreadPool(5);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        service.schedule(()-> System.out.println(sdf.format(new Date())+" schedule after 3s execute one time"), 3, TimeUnit.SECONDS );
        service.scheduleAtFixedRate(()-> System.out.println(sdf.format(new Date())+" scheduleAtFixedRate every from 2s, period by 5s"), 3,5, TimeUnit.SECONDS);
        service.scheduleWithFixedDelay(()-> System.out.println(sdf.format(new Date())+" scheduleWithFixedDelay from 2s, delay 2s"),2, 2, TimeUnit.SECONDS);
    }

    public static void main(String[] args) throws InterruptedException, ExecutionException {
        new TaskService().start();
    }
}
